package net.stock.controller;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.logging.Logger;
import java.util.logging.Level;

/**
 * User: naim
 * Date: Dec 28, 2009
 */
public class ExceptionHandler implements HandlerExceptionResolver {
    private Logger log = Logger.getLogger(getClass().getName());

    public ModelAndView resolveException(HttpServletRequest request,
                                         HttpServletResponse response,
                                         Object handler,
                                         Exception ex) {

        ModelAndView mv = new ModelAndView("error");
        Map model = mv.getModel();
        model.put("msg", ex.getMessage());
        log.log(Level.SEVERE, ex.getMessage(), ex.getCause());
        return mv;
    }
}
